<?php
function List_LocationRoot($parentId=0,$padding=0)
{
global $id,$language,$dbsql,$module,$type;
    $return="";
    
	//-----------------------------------------------------
	$sql_select = "select * from tbllocation
	where iParentId =$parentId and cLanguage='$language'
	order by iOrder";

	$rs=$dbsql->query($sql_select);
	
	while ( $result = $dbsql->fetch_array($rs) )
	{
        $child='';
        if($padding<20)
        {
		  $child= List_LocationRoot($result["iId"],$padding+20);
        }
		$return .="<div style='padding-left:".$padding."px;'";
		if($result["iId"] == $id)
		{
            $type    = "loc";
			$return .= " class='selected' ";
		}
		$return.="><a  href='?module=$module&id=".$result["iId"]."'>";
		$return.="&raquo;".$result["cName"]."</a></div>";
		$return.=$child;
	}
	return $return;
}

function ListLocationOption($select,$parentId=0,$padding=0)
{
global $dbsql,$language,$module,$id,$act;

    if($parentId==0 && $module=="location")
    {
        $options="<option value=0>------ Root-------</option>";
    }
    else if($parentId==0)
    {
        $options="<option value=-1>select location</option>";
    }
    else
    {
        $options='';
    }
    $space=str_repeat("&nbsp;",$padding);

    $sql_select="select iId,iParentId,cName from tbllocation where iParentId=$parentId ";
    if($module=="location" && $act!="add" && $id>0)
    {
        $sql_select.=" and iId != $id ";
    }
    $sql_select.=" order by iOrder";
    $rs=$dbsql->query($sql_select);
    while($result=$dbsql->fetch_array($rs))
    {
        if($select==$result['iId'])
        {
            $options.="<option value='".$result['iId']."' selected>".$space.$result['cName']."</option>";
        }else
        {
            $options.="<option value='".$result['iId']."'>".$space.$result['cName']."</option>";
        }
        $options.=ListLocationOption($select,$result['iId'],$padding+7);
    }
    return $options;
}

function hasChildLocation($idP)
{
    global $dbsql,$language;

    $sql_select="select iId from tbllocation where iParentId=$idP";
    $rs=$dbsql->query($sql_select);
    if($dbsql->num_rows($rs)>0)
    {
        return true;
    }else
    {
        return false;
    }
}

function ListPhotoLocation($id)
{
	global $language,$dbsql;

	$sql_select = "SELECT * FROM tbllocation_photo WHERE iParentId = '$id' order by iOrder";
    return $dbsql->load($sql_select);
}

function ListVideoLocation($idP)
{
    global $dbsql,$language;
    
    $sql_select = "select count(iId) as count from tbllocation_video where iParentId='$idP'";
    $result     = $dbsql->query_fetch($sql_select);
    $count_all  = $result['count'];
    if($count_all==0)return  array();
    
    list($lmstart,$lmlength)=Slit_Page($count_all);
    
    $sql_select = "SELECT * FROM tbllocation_video WHERE iParentId = '$idP' order by iOrder Asc limit $lmstart,$lmlength";
    return $dbsql->load($sql_select);
}
?>